package com.ruoyi.web.controller.laiqianba.account;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.wrapper.AccountProductInfoHisWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.AccountProductInfo;
import com.ruoyi.account.service.IAccountProductInfoService;
import com.ruoyi.web.wrapper.AccountProductInfoWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品账户信息Controller
 *
 * @author ruoyi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/account/productInfo")
public class AccountProductInfoController extends BaseController {
    @Autowired
    private IAccountProductInfoService accountProductInfoService;

    /**
     * 查询产品账户信息列表
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountProductInfo accountProductInfo) {

        if (!SecurityUtils.loginUserIsAdmin()){
            accountProductInfo.setOwnerId(SecurityUtils.getUserId());
        }

        startPage();
        List<Map<String, Object>> list = accountProductInfoService.selectAccountProductInfoMapList(accountProductInfo);
        list = new AccountProductInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出产品账户信息列表
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:export')")
    @Log(title = "产品账户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountProductInfo accountProductInfo) {
        List<AccountProductInfo> list = accountProductInfoService.selectAccountProductInfoList(accountProductInfo);
        ExcelUtil<AccountProductInfo> util = new ExcelUtil<AccountProductInfo>(AccountProductInfo.class);
        util.exportExcel(response, list, "产品账户信息数据");
    }

    /**
     * 获取产品账户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(accountProductInfoService.selectAccountProductInfoById(id));
    }

    /**
     * 新增产品账户信息
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:add')")
    @Log(title = "产品账户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountProductInfo accountProductInfo) {

        return accountProductInfoService.insertAccountProductInfo(accountProductInfo);
    }

    /**
     * 修改产品账户信息
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:edit')")
    @Log(title = "产品账户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountProductInfo accountProductInfo) {
        return accountProductInfoService.updateAccountProductInfo(accountProductInfo);
    }

    /**
     * 删除产品账户信息
     */
    @PreAuthorize("@ss.hasPermi('account:productInfo:remove')")
    @Log(title = "产品账户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(accountProductInfoService.deleteAccountProductInfoByIds(ids));
    }

}
